using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

using Microsoft.Xna.Framework;

using ProtoBuf;
using ProtoBuf.Serializers;

namespace SmlEngine.IO
{
    [Obsolete]
    public static class SerializationHelper
    {
        public static void Serialize<T>(this T data, string path)
        {
            using (var stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
                Serialize<T>(data, stream);
        }

        public static void Serialize<T>(this T data, Stream destination)
        {
            if (data == null)
                throw new ArgumentException("Cannot serialize a null value");

            Serializer.Serialize(destination, data);
        }

        public static void Deserialize<T>(this T destination, string path)
        {
            using (var stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read))
                destination = Deserialize<T>(stream);
        }

        public static T Deserialize<T>(string path)
        {
            using (var stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read))
                return Serializer.Deserialize<T>(stream);
        }

        public static void Deserialize<T>(this T destination, Stream source)
        {
            destination = Serializer.Deserialize<T>(source);
        }

        public static T Deserialize<T>(Stream source)
        {
            return Serializer.Deserialize<T>(source);
        }
    }
}
